package com.steven.ourcontest.contest.viewmodel

import com.steven.ourcontest.base.BaseViewModel
import com.steven.ourcontest.contest.api.ContestApi
import com.steven.ourcontest.team.bean.MatchInfo
import com.steven.ourcontest.utils.plusAssign

class AddContestViewModel : BaseViewModel() {

    fun addMatch(
        name: String,
        belong: String?,
        rank: String?,
        signUpStartTime: Long?,
        signUpEndTime: Long?,
        matchStartTime: Long?,
        matchEndTime: Long?,
        url: String? = null,
        success: () -> Unit,
        error: (msg: String) -> Unit
    ) {
        val matchInfo =
            MatchInfo(0, name, belong, rank, signUpStartTime, signUpEndTime, matchStartTime, matchEndTime, url)
        disposed += ContestApi.instance.addMatch(matchInfo)
            .subscribe({
                success.invoke()
            }, {
                it.message?.let { it1 -> error.invoke(it1) }
                it.printStackTrace()
            })
    }
}